use([
    "public/javascripts/service/order_manageinfo_tradeService.js",
    "public/javascripts/widget/slider/slider.js",
], function (order_manageinfo_tradeService, SliderComponent) {
    var PageComponent = React.createClass({
        componentDidMount: function () {
            this.getOrderInfo();
        },
        getInitialState: function () {
            return {
                orderNo: this.props.data.oid,
                info: '',
                userType: ''
            }
        },

        getOrderInfo: function () { //获取订单详情
            var _this = this;
            var userType = cookie.get('userType');
            var customerType;
            if (userType == 2 || userType == 3) {
                this.setState({userType: 1});
                customerType = 1;
            }
            if (userType == 256) {
                this.setState({userType: 2});
                customerType = 2;
            }
            order_manageinfo_tradeService.getOrderInfo({
                urlParams: {
                    'orderNo': this.state.orderNo,
                    'customerType': customerType
                }
            }, function (res) {
                if (res.errorCode === 0) {
                    if (res.data.orderGoods && res.data.orderGoods.length) {
                        res.data.orderGoods.forEach(function (item) {
                            if (res.data.orderStatus.toLowerCase() == 'signed') {   //已签收
                                item.countNumber = item.goodsNum;
                            } else {
                                if (item.minLimit == null && item.maxLimit == null) {
                                    item.minLimit = item.goodsNum;
                                }
                                if (item.minLimit && item.maxLimit) {
                                    item.countNumber = item.minLimit + '—' + item.maxLimit;
                                } else {
                                    item.countNumber = item.minLimit || item.maxLimit;
                                }
                            }
                        });
                    }

                    _this.setState({info: res.data});
                }
            });
        },

        getOrderPdf: function (type) {
            order_manageinfo_tradeService.getOrderPdf({
                seatParams: {orderNo: this.state.info.orderNo},
                urlParams: {type: type}
            }, function (res) {
                window.open(res.data);
            })
        },

        render: function () {
            var info = this.state.info;
            var list = this.state.info.orderGoods ? this.state.info.orderGoods : [];
            return ~init;
        }
    });
    if (typeof ReactDOM != "undefined") {
        ReactDOM.render(<PageComponent data={storage}/>, document.getElementById('container'));
    }
    module.exports = PageComponent;
});
